package cn.zx.org.service.impl;

import cn.zx.basic.PageList;
import cn.zx.org.domain.Department;
import cn.zx.org.mapper.DepartmentMapper;
import cn.zx.org.query.DepartmentQuery;
import cn.zx.org.service.IDepartementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartementServiceImpl implements IDepartementService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public Department queryOne(Long id) {
        return departmentMapper.loadOne(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.loadAll();
    }

    @Transactional
    @Override
    public void add(Department department) {
        departmentMapper.insert(department);
    }

    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery departmentQuery) {
        Long count = departmentMapper.queryCount();
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        PageList<Department> departmentPageList = new PageList<>(count, rows);
        return departmentPageList;
    }
}
